package com.jinlia.show.modules.base.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinlia.show.modules.base.system.entity.ErrandOrder;
import com.jinlia.show.modules.base.system.entity.OrderLog;
import com.jinlia.show.modules.base.system.mapper.OrderLogMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class OrderLogMapperService extends ServiceImpl<OrderLogMapper, OrderLog> {
    @Autowired
    private ErrandOrderMapperService errandOrderMapperService;

    /**
     * 订单操作记录
     *
     * @param orderBizType PD配送单|PT跑腿单|ZP支付单
     * @param orderBizId   业务订单id
     * @param actionName   动作名称
     * @param actionResult 备注
     */
    public void addOrderLog( String orderBizType, Long orderBizId, String actionName, String actionResult) {
        OrderLog orderTrack = new OrderLog();
        orderTrack.setActionName(actionName);
        orderTrack.setActionResult(actionResult);
        this.save(orderTrack);
    }
    /**
     * 订单操作记录
     *
     * @param orderBizType PD配送单|PT跑腿单|ZP支付单
     * @param orderBizId   业务订单id
     * @param actionName   动作名称
     * @param actionResult 备注
     */
    public void addOrderLog( String orderBizType, Long orderBizId, String actionName, String actionResult, String remark) {
        OrderLog orderTrack = new OrderLog();
        orderTrack.setActionName(actionName);
        orderTrack.setActionResult(actionResult);
        orderTrack.setRemark(remark);
        this.save(orderTrack);
    }

    public List<OrderLog> saleOrder(Long id) {
        //销售订单
        List<OrderLog> list = this.lambdaQuery().list();
        //配送单
        //跑腿单
        return list;
    }

    public List<OrderLog> deliveryOrder(Long id) {
        //跑腿单
        List<ErrandOrder> listErrandOrder = errandOrderMapperService.lambdaQuery().eq(ErrandOrder::getDeliveryOrderId, id).list();
        List<Long> collectId = listErrandOrder.stream().map(ErrandOrder::getId).collect(Collectors.toList());
        collectId.add(id);
        List<OrderLog> listOrderLog = this.lambdaQuery()
//                .in(OrderLog::getOrderBizId, collectId)
                .list();
        return listOrderLog;
    }

    public List<OrderLog> errandOrder(Long id) {
        List<OrderLog> list = this.lambdaQuery().list();
        return list;
    }
}
